package apiUtils;

import com.google.gson.Gson;

import org.json.JSONException;
import org.json.JSONObject;

import apiUtils.params.Params;
import appUtils.PayDESUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2017/5/3.
 */

public abstract class APISHelper {
    protected static final Gson sGon = new Gson();
    private static final BaseAPIS sBaseAPIS = BaseAPIS.getInstance();

    protected abstract Params initParams() throws JSONException;

    protected String desDecode(JSONObject object) throws JSONException {
        String msg = object.getString("msg");
        String nonce = object.getString("timeStamp");
        return PayDESUtil.decode(nonce, msg);
    }

    protected void get(String tag, String url, CallBack callback) throws JSONException {
        sBaseAPIS.get(tag, url, initParams(), callback);
    }

    protected void post(String tag, String url, CallBack callback) throws JSONException {
        sBaseAPIS.post(tag, url, initParams(), callback);
    }

    protected void subscribe(Consumer<Integer> consumer) {
        Observable.just(1).observeOn(AndroidSchedulers.mainThread()).subscribe(consumer);
    }
}
